package com.dcm.item.controller;

import com.dcm.common.annotation.EnableResponseBodyAdvice;
import com.dcm.item.entity.SpecificationEntity;
import com.dcm.item.service.SpecService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Classname: SprcificationController
 * @Author Mengxiangjian
 * @Date: 2021/3/23 14:23
 * @Version V 1.0
 */
@Api(tags = "SpecificationController")
@RestController
@RequestMapping("/spec")
@EnableResponseBodyAdvice
public class SpecificationController {

    @Autowired
    private SpecService specService;

    /**
     * findAll 查询所有
     *
     * @return
     */
    @ApiOperation("查询所有")
    @GetMapping("/findAll")
    public List<SpecificationEntity> findAll() {
        return specService.findAll();
    }

    /**
     * @param name
     * @return
     */
    @ApiOperation("根据name查询")
    @PostMapping("/find")
    public SpecificationEntity find(@RequestParam(value = "name", required = false) String name) {
        return specService.find(name);
    }

    /**
     * 添加
     *
     * @param specification
     */
    @ApiOperation("添加")
    @PostMapping("/add")
    public void add(SpecificationEntity specification) {
        specService.add(specification);
    }

    /**
     * 更新 根据  specification
     *
     * @param specification
     */
    @ApiOperation("修改")
    @PutMapping("/update")
    public void update(SpecificationEntity specification) {
        specService.update(specification);
    }

    /**
     * 根据id 删除
     *
     * @param id
     */
    @ApiOperation("根据id删除")
    @PostMapping("/delete")
    public void delete(Long id) {
        specService.delete(id);
    }

    /**
     * 批量删除
     *
     * @param ids
     */
    @ApiOperation("批量删除")
    @DeleteMapping("/deletes")
    public void deletes(@RequestParam("list") List<Long> ids) {
        specService.deletes(ids);
    }

    @ApiOperation("分页")
    @GetMapping("findPage")
    public PageInfo<SpecificationEntity> findPage(@RequestParam(value = "pageSize", required = false) Integer pageSize,
                                                  @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return specService.findPage(currentPage, pageSize);
    }
}
